<template>
    <el-tabs type="border-card" class="edittabform">
        <el-tab-pane label="数据">
            <el-row type="flex" class="editformitem" align="middle">
                <el-col :span="8" class="editlabel">
                    <span>数据表格</span>
                </el-col>
                <el-col :span="16" class="editcontent">
                    <el-select v-model="obj.tableData.tableId" filterable clearable placeholder="请选择数据" size="mini"
                        @change="tableSelectChange">
                        <el-option v-for="item in dataTableList" :key="item.id" :label="item.name" :value="item.id">
                        </el-option>
                    </el-select>
                </el-col>
            </el-row>
            <el-row type="flex" class="editformitem" align="middle">
                <el-col :span="8" class="editlabel">
                    <span>数值</span>
                </el-col>
                <el-col :span="16" class="editcontent">
                    <el-select v-model="obj.tableData.itemId" filterable clearable placeholder="请选择数据" size="mini">
                        <el-option v-for="item in columnData" :key="item.id" :label="item.name"
                            :value="item.id"></el-option>
                    </el-select>
                </el-col>
            </el-row>
            <el-row type="flex" class="editformitem">
                <el-col :span="8" class="editlabel">
                    <span>最大值</span>
                </el-col>
                <el-col :span="16" class="editcontent">
                    <input v-model.number="obj.tableData.maxNumber" class="miniinput" type="number" />
                </el-col>
            </el-row>
            <el-row type="flex" class="editformitem" align="middle">
                <el-col :span="8" class="editlabel">
                    <span>小数点位</span>
                </el-col>
                <el-col :span="16" class="editcontent">
                    <input v-model.number="obj.tableData.decimal" class="miniinput" type="number" />
                </el-col>
            </el-row>
            <el-row type="flex" class="editformitem">
                <el-col :span="8" class="editlabel">
                    <span>数字字体</span>
                </el-col>
                <el-col :span="16" class="editcontent">
                    <input v-model.number="obj.tableData.fontSize" class="miniinput" type="number" />
                    <el-color-picker v-model="obj.tableData.fontColor" size="small" show-alpha :predefine="predefineColors"
                        popper-class="mycolorview" @active-change="setColorChange(obj.tableData, 'fontColor', $event)" />
                    <div class="fontstylev">
                        <div :class="['fontitem', { 'active': obj.tableData.fontWeight == 'bold' }]"
                            @click="setFontStyle('fontWeight', obj.tableData, 'fontWeight')"><i
                                class="iconfont icon-zitijiacu"></i>
                        </div>
                        <div :class="['fontitem', { 'active': obj.tableData.fontStyle == 'italic' }]"
                            @click="setFontStyle('fontStyle', obj.tableData, 'fontStyle')"><i
                                class="iconfont icon-zitixieti"></i>
                        </div>
                    </div>
                </el-col>
            </el-row>
            <template v-if="obj.tableData.styleTemplate == 0">
                <el-row type="flex" class="editformitem" align="middle">
                    <el-col :span="8" class="editlabel">
                        <span>数值背景</span>
                    </el-col>
                    <el-col :span="16" class="editcontent">
                        <el-color-picker v-model="obj.tableData.valueColor" size="small" show-alpha
                            :predefine="predefineColors" popper-class="mycolorview"
                            @active-change="setColorChange(obj.tableData, 'valueColor', $event)" />
                    </el-col>
                </el-row>
                <el-row type="flex" class="editformitem" align="middle">
                    <el-col :span="8" class="editlabel">
                        <span v-if="obj.type == 'LiquidFill'">水位颜色</span>
                        <span v-else>图表背景</span>
                    </el-col>
                    <el-col :span="16" class="editcontent">
                        <el-color-picker v-model="obj.tableData.rateBackageColor" size="small" show-alpha
                            :predefine="predefineColors" popper-class="mycolorview"
                            @active-change="setColorChange(obj.tableData, 'rateBackageColor', $event)">
                        </el-color-picker>
                    </el-col>
                </el-row>
            </template>
            <el-row type="flex" class="editformitem">
                <el-col :span="8" class="editlabel">
                    <span>样式选择</span>
                </el-col>
                <el-col :span="16" class="editcontent">
                    <el-radio-group v-model="obj.tableData.styleTemplate" class="styletempradio" @change="setTempType">
                        <el-radio :label="0">普通</el-radio>
                        <el-radio :label="1">带刻度</el-radio>
                        <el-radio :label="2">渐变</el-radio>
                        <el-radio :label="3">动效</el-radio>
                    </el-radio-group>
                </el-col>
            </el-row>
            <el-row type="flex" class="editformitem" align="middle">
                <el-col :span="8" class="editlabel">
                    <span>刷新间隔</span>
                </el-col>
                <el-col :span="16" class="editcontent">
                    <input type="number" v-model.number="obj.tableData.reloadTime" class="miniinput"
                        @change="reloadTimeChangeHandle" />
                    <span>秒</span>
                </el-col>
            </el-row>
        </el-tab-pane>
        <el-tab-pane label="样式">
            <el-collapse v-model="collapseActives" class="edittypeform">
                <el-collapse-item title="标题" name="4">
                    <title-form :predefineColors="predefineColors" :obj="obj" :setColorChange="setColorChange"
                        :setFontStyle="setFontStyle"></title-form>
                </el-collapse-item>
            </el-collapse>
        </el-tab-pane>
        <el-tab-pane label="布局">
            <box-form :predefineColors="predefineColors" :obj="obj" :setColorChange="setColorChange"></box-form>
        </el-tab-pane>
    </el-tabs>
</template>

<script>
export default {
    name: "RateForm",
    props: {
        predefineColors: Array,
        obj: Object,
        dataTableList: Array,
        columnData: Array,
        tableSelectChange: Function,
        deleteDataYinfo: Function,
        setColorChange: Function,
        setFontStyle: Function,
        reloadTimeChangeHandle: Function,
    },
    model: {
        prop: "obj",
        event: "change",
    },
    components: {
        TitleForm: () => import('../mixin/TitleForm.vue'),
        BoxForm: () => import('../mixin/BoxForm.vue'),
    },
    methods: {
        setTempType() {
            let type = this.obj.tableData.styleTemplate;

            if (type == 0) {
                this.obj.tableData.fontColor = "#666666";
                this.obj.tableData.fontSize = 36;
                this.obj.style.backgroundColor = "#ffffff";
            } else if (type == 1) {
                this.obj.tableData.fontColor = "#ffffff";
                this.obj.tableData.fontSize = 30;
                this.obj.style.backgroundColor = "#051F54";
            } else if (type == 2) {
                this.obj.tableData.fontColor = "#ffffff";
                this.obj.tableData.fontSize = 30;
                this.obj.style.backgroundColor = "#000000";
            } else if (type == 3) {
                this.obj.tableData.fontColor = "#ffffff";
                this.obj.tableData.fontSize = 30;
                this.obj.style.backgroundColor = "#000000";
            }
        }
    }
}
</script>